package com.bjpowerndoe.ylb.web.controller;

import cn.hutool.core.bean.BeanUtil;
import com.bjpowerndoe.ylb.common.AppTools;
import com.bjpowerndoe.ylb.domain.RechargeRecordPO;
import com.bjpowerndoe.ylb.web.enums.CodeEnum;
import com.bjpowerndoe.ylb.web.model.CommonResult;
import com.bjpowerndoe.ylb.web.model.vo.RechargeRecordVO;
import com.bjpowerndoe.ylb.web.service.inter.RechargeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@Api(tags = "充值模块")
@RequiredArgsConstructor
@RestController
public class RechargeController {

    private final RechargeService rechargeService;


    @ApiOperation("查询更多充值记录")
    @GetMapping("/recharge/more")
    public CommonResult queryRechargeList(@RequestHeader("uid") Integer uid,
                                          @RequestParam(required = false) Integer pageNo,
                                          @RequestParam(required = false,defaultValue = "6") Integer pageSize){
        CommonResult commonResult = CommonResult.fail(CodeEnum.REQUEST_PARAM_ERR);
        if( uid > 0 ){
            pageNo = AppTools.defaultPageNo(pageNo);
            pageSize = AppTools.defaultPageSize(pageSize);
            List<RechargeRecordPO> rechageList = rechargeService.queryRechargeListByUid(uid, pageNo, pageSize);

            commonResult = CommonResult.ok(BeanUtil.copyToList(rechageList, RechargeRecordVO.class));

        }
        return commonResult;

    }
}
